<?php
header("content-type:text/html;charset=utf-8");
$mysqli = new mysqli("localhost", "root", "123", "my_test");
$mysqli->set_charset("utf8");
$id = $_GET['id'];

$query = "SELECT * FROM users WHERE id=$id";
$res = $mysqli->query($query);
if ($res && $res->num_rows) {
    $row = $res->fetch_assoc();
} else {
    echo "出错";
}
?>

<!doctype html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>用户列表</title>
    <style>
        body {
            margin: 0;
            padding: 0;
            text-align: center;
            font: 12px/150% Arial, Verdana, "\5b8b\4f53";
            color: #666;
            background: #fff
        }

        h2 {
            margin-top: 150px;
        }

        p {
            text-align: right;
            margin: 0 auto;
            width: 80%;
        }

        form p {
            margin: 18px auto;
            text-align: left;
        }

        a {
            color: #666;
            text-decoration: none;
        }

        a:hover {
            color: #333;
            text-decoration: underline;
        }

        div {
            width: 40%;
            margin: 0 auto;
            background: #eee;
            padding: 30px 0;
        }

        label {
            width: 25%;
            display: inline-block;
            text-align: right;
        }

        input {
            width: 50%;
            height: 25px;
            margin-left: 40px;
            padding: 0 5px;
            font-size: 18px;
            outline: none;
            border: 1px solid #ccc;
            color: #777;
        }

        input:focus {
            border: 1px solid #00c1ff;
        }

        .action input {
            width: 25%;
            margin: 0;
            padding: 0;
            border: none;
            display: inline-block;
            outline: none;
            cursor: pointer;
            font-size: 16px;
            letter-spacing: 5px;
            height: 32px;
            line-height: 32px;
            color: #fff;
            background: #00c1ff;
        }

        p.action {
            text-align: center;
            margin-top: 36px;
        }

        .action span {
            display: inline-block;
            width: 5%;
        }
    </style>
</head>
<body>
<h2>编辑用户</h2>
<p><a href="user_list.php">返回列表</a></p>
<div class="content">
    <form action="user_response.php?action=edit&id=<?php echo $id; ?>" method="post">
        <p>
            <label for="username">用户名</label><input type="text" name="username" value="<?php echo $row['username']; ?>"
                                                    autofocus>
        </p>
        <p>
            <label for="username">密码</label><input type="password" name="password"
                                                   value="<?php echo $row['password']; ?>">
        </p>
        <p>
            <label for="username">年龄</label><input type="number" name="age" value="<?php echo $row['age']; ?>">
        </p>
        <p class="action">
            <input type="submit" value="更新"><span></span><input type="reset" value="重置">
        </p>
    </form>
</div>

</body>
</html>
